﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RookieLibSharp.Configuration;
using RookieLibSharp.WinApi;
namespace BirthdayRemainder
{
    public partial class FrmRemainder : Form
    {
        Timer tCount = new Timer();
        int nCount = 20;
        public FrmRemainder()
        {
            InitializeComponent();
            tCount.Tick += new EventHandler(tCount_Tick);
            tCount.Enabled = true;
            tCount.Interval = 1000;
        }

        private void FrmRemainder_Load(object sender, EventArgs e)
        {
            this.Icon = BirthdayRemainder.Properties.Resources.ico_main;
            this.rtbRemainder.Text = Funcs.IsRegSucess()? Funcs.GetRemindStr():"功能受限，注册后使用";
            this.LabCount.Text = nCount.ToString();
            this.LabCount.Visible = false;
            Point point = new Point();
            point.X = Screen.PrimaryScreen.WorkingArea.Right - this.Width;
            point.Y = Screen.PrimaryScreen.WorkingArea.Bottom - this.Height;
            this.Location = point;
            AnimateWindowFlags flag = AnimateWindowFlags.AW_ACTIVATE;
            flag |= AnimateWindowFlags.AW_SLIDE | AnimateWindowFlags.AW_VER_NEGATIVE;

            Win32Api.AnimateWindow(this.Handle, 600, flag);
            this.LabCount.Visible = true;
        }

        private void ckbNotRemaind_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox ckb = (CheckBox)sender;
            if (ckb.Checked)
            {
                Cfg.WriteConfig(GlobalValue.SFT_CFG, GlobalValue.SFT_CFG_NOT_FRM_REMAIND, true);
            }
        }
        private void tCount_Tick(object sender, EventArgs e)
        {
            nCount--;
            this.LabCount.Text = nCount.ToString();
            if (nCount <= 0)
            {
                CloseFrm();
            }
        }
        private delegate void dg_CloseFrm();
        private void CloseFrm()
        {
            if (this.InvokeRequired)
            {
                dg_CloseFrm method = CloseFrm;
                this.Invoke(method);
            }
            else
            {
                this.Close();
            }
        }

        private void FrmRemainder_FormClosing(object sender, FormClosingEventArgs e)
        {
            Win32Api.AnimateWindow(this.Handle, 200, AnimateWindowFlags.AW_BLEND | AnimateWindowFlags.AW_HIDE);
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
